<template lang="pug">
  .come-in
    | 正在进入...
</template>

<script>
import UserInfo from './helpers/user_info'

export default {
  name: 'WxCallback',
  methods: {
    toState () {
      if (this.$route.query.state) {
        this.$router.replace(this.$route.query.state)
      } else {
        this.$router.push({name: 'Home'})
      }
    }
  },
  mounted () {
    this.$http.post('/proxy/api/sessions', {code: this.$route.query.code}).then((res) => {
      if (!res.data.error_type) {
        UserInfo.set(res.data)
      }
      this.toState()
    })
  },
  computed: {
    user_info () {
      return UserInfo.get()
    }
  }
}
</script>
<style lang="sass">
@import './styles/color.sass';
.come-in
  padding: 15px
  text-align: center
</style>
